home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.08 Aug 89 / POOPDraw Code ƒ / APPL DoCommand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-13  |  4.8 KB  |  218 lines  |  [TEXT/KAHL]

  1. /********************************************************************/
  2. /*                        SOURCE CODE FILE                            */
  3. /********************************************************************/
  4. /*
  5. *   >>>    File name:        APPL DoCommand.c    
  6. *
  7. *      >>>    Purpose:        Application specific menu handlers
  8. *     >>>    Project:        PoopDraw    Version 1        
  9. *     >>>    Date:            May 23, 1989
  10. *      >>>    By:                Adam Treister
  11. *
  12. */
  13. /********************************************************************/
  14. /*    For Your Information            1802 Hillside Rd. SB CA 93101    */
  15. /********************************************************************/
  16.  
  17. #include "PoopDrawInc"
  18.  
  19. void     DoMenuCommand    (long MenuSelectResult);
  20. void     ApplicationInit    (void);
  21. void     ApplicationShutDown    (void);
  22.     
  23. private DoApple(int    TheItem);
  24. private DoFile(int    TheItem);    
  25. private DoEdit(int    TheItem);
  26. private DoObject(int    TheItem);
  27.  
  28. private void About(void);
  29. private void Help(void);
  30. private void File_New(void);
  31. private void File_Open(void);
  32. private void File_Close(void);
  33. private Boolean File_Save(void);
  34. private Boolean File_SaveAs(void);
  35. private void DoAModal(int id);
  36.  
  37. /*------------------------------------------------------------------*/
  38.  
  39. void ApplicationInit()
  40. {
  41.     File_New();
  42. }
  43.  
  44. /*------------------------------------------------------------------*/
  45.  
  46. void ApplicationShutDown()
  47. {
  48. }
  49. /*------------------------------------------------------------------*/
  50.  
  51. void DoMenuCommand(MenuSelectResult)
  52. long    MenuSelectResult;
  53. {    
  54.     register int TheMenu,TheItem;
  55.  
  56.     TheMenu = HiWord(MenuSelectResult);    
  57.     TheItem = LoWord(MenuSelectResult);
  58.  
  59.     switch (TheMenu)
  60.     {
  61.     
  62.         case 1000:    DoApple(TheItem);        break;
  63.         case 1001:    DoFile(TheItem);        break;
  64.         case 1002:    DoEdit(TheItem);        break;
  65.         case 1003:    DoObject(TheItem);        break;
  66.  
  67.     }
  68.     HiliteMenu(0);
  69. }
  70. /*------------------------------------------------------------------*/
  71.  
  72. DoApple(TheItem)
  73. int        TheItem;
  74. {
  75.             Str255        daName;
  76.             GrafPtr     savePort;
  77.     extern    MenuHandle    Menus[];
  78.     
  79.     if (TheItem == 1)            DoAModal(AboutID);    
  80.     else if (TheItem == 2)        DoAModal(HelpID);    
  81.     else 
  82.     {
  83.         GetItem(Menus[0], TheItem, daName);
  84.         
  85.         GetPort(&savePort);
  86.         (void) OpenDeskAcc(daName);
  87.         SetPort(savePort);
  88.     }
  89. }
  90.  
  91. /*------------------------------------------------------------------*/
  92.  
  93. DoFile(TheItem)
  94. int    TheItem;
  95. {    extern Boolean MillerTime;
  96.     
  97.     switch (TheItem)
  98.     {
  99.         case 1:        File_New();            break;
  100.         case 2:        File_Open();        break;
  101.         case 3:        File_Close();        break;
  102.         case 4:        File_Save();        break;
  103.         case 5:        File_SaveAs();        break;
  104.                 
  105.         case 7:        MillerTime = TRUE;    break;
  106.                 
  107.         default:    Oops("\pUnknown item in File Menu", 0, TRUE);
  108.     }
  109. }
  110.  
  111. /*------------------------------------------------------------------*/
  112.  
  113. DoEdit(TheItem)
  114. int    TheItem;
  115. {
  116.     /* sorry,not implemented in this version */
  117.     /* Notes: 
  118.         Undo could be implemented by saving a copy of the object and select lists.
  119.         Objects could be written to the clipboard in a manner similar to 
  120.             writing them to a file (ie use PACK and UNPACK)
  121.     */
  122. }
  123.  
  124. /* ------------------------------------------------------------ */
  125. /*                                                                */
  126. /*                DoObject                                        */
  127. /*                                                                */
  128. /*                                                                */
  129. /* ------------------------------------------------------------ */
  130.  
  131. DoObject(TheItem)
  132. int    TheItem;
  133. {    
  134.     WindowPtr wP = MyFrontWindow();
  135.     switch (TheItem)
  136.     {
  137.  
  138.         case 1:        WDispatch(wP,BRINGTOFRONT,NULL);    break;
  139.         case 2:        WDispatch(wP,SENDTOBACK,NULL);        break;
  140.                 
  141.         case 4:        WDispatch(wP,GROUP,NULL);            break;
  142.         case 5:        WDispatch(wP,UNGROUP,NULL);        break;
  143.                 
  144.         default:            break;
  145.     }
  146. }
  147. /*------------------------------------------------------------------*/
  148.  
  149. void DoAModal(id)
  150. int id;
  151. {
  152.     DialogPtr dlog;
  153.     int item;
  154.     Rect r;
  155.     int lft,top;
  156.     
  157.     dlog = GetNewDialog(id,NULL,-1L);
  158.     r = screenBits.bounds;
  159.     lft = ( Width(r) - Width(dlog->portRect) ) / 2;
  160.     top = ( Height(r) - Height(dlog->portRect) ) / 2;
  161.  
  162.     MoveWindow(dlog,lft,top,true);
  163.     ShowWindow(dlog);
  164.     SetPort(dlog);
  165.     do ModalDialog(NULL,&item);
  166.     while (item != 1);
  167.     DisposDialog(dlog);
  168. }
  169. /* ============================================================ */
  170. /*                                                                */
  171. /*                THE FILE MENU HANDLERS                            */
  172. /*                                                                */
  173. /* ============================================================ */
  174.  
  175. void File_New()
  176. {
  177.     WindowPtr wP;
  178.  
  179.     New(DRAWWIND,NULL,&wP);
  180. }
  181.  
  182. /*------------------------------------------------------------------*/
  183.  
  184. void File_Open()
  185. {
  186.     WindowPtr wP;
  187.     Handle h;
  188.     
  189.     if (h =  ReadFileToHandle())
  190.     {
  191.         New(DRAWWIND,NULL,&wP);
  192.         WDispatch(wP,LOAD,h);
  193.     }
  194. }
  195.  
  196. /*------------------------------------------------------------------*/
  197. void File_Close()
  198. {
  199.     WDispatch(MyFrontWindow(),CLOSE,NULL);
  200. }
  201.  
  202. /*------------------------------------------------------------------*/
  203.  
  204. Boolean File_Save()
  205. {
  206.     long DoSaveAs = NULL;
  207.     WDispatch(MyFrontWindow(),SAVE,&DoSaveAs);
  208. }
  209.  
  210. /*------------------------------------------------------------------*/
  211.  
  212. Boolean File_SaveAs()
  213. {
  214.     long DoSaveAs = 1L;
  215.     WDispatch(MyFrontWindow(),SAVE,&DoSaveAs);
  216. }
  217. /********************************************************/
  218.